package com.sanjiahantang.youjiarole.module.common.views.impl;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.uilibrary.views.TagGroup;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.module.common.beans.PersonGoodsBean;
import com.sanjiahantang.youjiarole.module.common.presenters.MeAccountPresenter;
import com.sanjiahantang.youjiarole.module.common.views.MeAccountView;
import com.sanjiahantang.youjiarole.module.goods.views.impl.GoodsListActivity;
import com.sanjiahantang.youjiarole.module.me.order.beans.ShopListBean;
import com.sanjiahantang.youjiarole.module.me.order.views.impl.OrderActivity;
import com.sanjiahantang.youjiarole.utils.FileUtils;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 我的物料管理
 * Created by admin on 2017/10/28.
 */

public class MyMaterialMangerActivity extends BaseMvpActivity<MeAccountView, MeAccountPresenter> implements MeAccountView, View.OnClickListener {
    private ListView detail_list;
    QuickAdapter<PersonGoodsBean.Data> adapter;
    View fl_Left,flIcon3;
    TextView title,txtRight;

    @Override
    public MeAccountPresenter initPresenter() {
        return new MeAccountPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_material_manager);

        detail_list = (ListView) findViewById(R.id.detail_list);
        fl_Left = findViewById(R.id.fl_Left);
        fl_Left.setOnClickListener(this);
        flIcon3=findViewById(R.id.flIcon3);
        flIcon3.setOnClickListener(this);
        flIcon3.setVisibility(View.VISIBLE);
        txtRight= (TextView) findViewById(R.id.txtRight);
        title = (TextView) findViewById(R.id.title);
        presenter.MyMeteriaManager($this);

    }

    @Override
    public void initData() {
        presenter.setOncliclkLisener(new OnLoadListener() {
            @Override
            public void onLoad(Object content) {
                Object[] param = (Object[]) content;
                switch ((int) param[0]) {
                    case ACCOUNT_TYPE_COMMEN:
                        adapter = new QuickAdapter<PersonGoodsBean.Data>($this, R.layout.item_order_goods, (List<PersonGoodsBean.Data>) param[1]) {
                            @Override
                            protected void convert(BaseAdapterHelper helper, final PersonGoodsBean.Data item) {
                                ImageView imageView = helper.getView(R.id.imgGoods);
                                helper.setText(R.id.txtTitle, item.getRecordName());
                                helper.setText(R.id.txtPrice, item.getPrice());
                                helper.setText(R.id.txtNumber, item.getCount());
                                TagGroup tagGroup = (TagGroup) helper.getView(R.id.tgScale);
                                String[] i=item.getMgpiValue().split(",");
                                tagGroup.setTags(i);
                                Picasso.with(context).load(FileUtils.rePath(item.getUrl())).placeholder(RES_ID_GOODS_DEFAULT).into(imageView);

                                helper.getView().setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        Intent intent = new Intent($this, OrderActivity.class);
                                        intent.putExtra(KEY_TYPE,ORDER_TYPE_CLOSE);
                                        ShopListBean.Data data = new ShopListBean.Data();
                                        data.setOrderCode(item.getOrderRecordCode().substring(0,item.getOrderRecordCode().length() - 2));
                                        Bundle b = new Bundle();
                                        b.putSerializable("goods",data);
                                        intent.putExtra(KEY_PARAM,b);
                                        startActivity(intent);
                                    }
                                });
                            }
                        };
                        detail_list.setAdapter(adapter);
                        break;

                }
            }
        });
        title.setText("物料管理");
        txtRight.setText("新增");
    }

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fl_Left:
                finish();
                break;
            case R.id.flIcon3:
                startActivity(new Intent($this, GoodsListActivity.class).putExtra("isExperienceShow",1));
                break;
        }

    }

}
